/**
 * @file form action
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import {
  REQ_FETCH_WIZARD,
  REC_FETCH_WIZARD,

  REQ_FETCH_STEP,
  REC_FETCH_STEP,

  REQ_SAVE_STEP,
  REC_SAVE_STEP,

  REQ_SAVE_WIZARD,
  REC_SAVE_WIZARD,

  UPDATE_STEP,
  RESET_WIZARD,

  REQ_ACTION_WIZARD,
  REC_ACTION_WIZARD
} from './action-types';
import {createAjaxAction, createScopedAction} from '../renderer';

export const resetWizard = (name, data = {}) => {
  const action = createScopedAction(name, RESET_WIZARD);
  return dispatch => dispatch(action(data));
};

export const fetchWizard = createAjaxAction('get', REQ_FETCH_WIZARD, REC_FETCH_WIZARD);
export const fetchStep = createAjaxAction('get', REQ_FETCH_STEP, REC_FETCH_STEP);
export const saveStep = createAjaxAction('post', REQ_SAVE_STEP, REC_SAVE_STEP);
export const saveWizard = createAjaxAction('post', REQ_SAVE_WIZARD, REC_SAVE_WIZARD);

export const updateStep = (name, data) => {
  const action = createScopedAction(name, UPDATE_STEP);
  return dispatch => dispatch(action(data));
};

export const doAction = createAjaxAction('post', REQ_ACTION_WIZARD, REC_ACTION_WIZARD);

